<?php 

namespace api\admin\controller;

use cmf\controller\RestBaseController;
use think\Db;
use think\Validate;
use api\admin\model\ToiletFlowModel;
use api\admin\controller\ToiletSumController;


class SumController extends RestBaseController
{
	public $mac;
    public $type = 0;  //0 --7天 1--最近30天 2-- 自定义月份 3 -- 年份
    public $DateTime = 0;


	public function __construct($value = '')
    {
        parent::__construct();
        //检测用户登录状态
        // $this->getUserId();
    }


    //获取公厕流量
    public function getToiletFlow()
    {
    	// 周,月,年
    	// http://toilet.wmqt.net/api/admin/SUM/getToiletFlow?token=af4d6fbf224808dc4eaf3dffa35d08623b90d4c5d3e5d2c1aa6386c7e827a620&device_type=web&mac=2C:6A:6f:00:6B:9C&type=2

    	$param = $this->request->param();

    	if (!isset($param['mac'])) {
            $this->error('请求错误！');
    	}

	    $mac = $param['mac'];
    	$type = isset($param['type']) ? $param['type'] :0; //周 月 年
    	$dateTime = isset($param['date_time']) ? $param['date_time'] : strtotime(time()); //周 月 年
		
    	//获取时间线
		$ToiletFlow = new ToiletFlowModel();
    	$result['line'] = $ToiletFlow->getLineDate($type,$dateTime);
    	//根据时间线查询数据
        $res = $ToiletFlow->getFlowData($mac,$type,$result['line']);
        $result['count'] = $res['count'];
        $result['man_count'] = $res['man_count'];
        $result['woman_count'] = $res['woman_count'];
        
        $result['man_list'] = $res['man_list'];
        $result['woman_list'] = $res['woman_list'];
        $result['other_list'] = $res['other_list'];
        $result['count_list'] = $ToiletFlow->getCountList($res);


    	$this->success('success',$result);

    }

    //获取满意度
    public function getSatisfactionSum($value='')
    {

    	// http://toilet.wmqt.net/api/admin/SUM/getSatisfactionSum?token=af4d6fbf224808dc4eaf3dffa35d08623b90d4c5d3e5d2c1aa6386c7e827a620&device_type=web&mac=2C:6A:6f:00:6B:9C&type=0
    	//月,年

    	$param = $this->request->param();

    	if (!isset($param['mac'])) {
            $this->error('请求错误！');
    	}

	    $mac = $param['mac'];
    	$type = isset($param['type']) ? $param['type'] :0; //周 月 年
    	$dateTime = isset($param['date_time']) ? $param['date_time'] : strtotime(time()); //周 月 年
    	// 周,月,年
		
		$ToiletFlow = new ToiletFlowModel();
    	$result['line'] = $ToiletFlow->getLineDate($type,$dateTime);
        $res = $ToiletFlow->getSatisfactionData($mac,$type,$result['line']);
        $result['name']  = $res['name'];
        $result['data']  = $res['val'];
        $result['sector']  = $ToiletFlow->getSectorData($res);
        
    	$this->success('success',$result);


    }

    //获取投诉检测
    public function getSatisfactionTagSum($value='')
    {

    	$param = $this->request->param();

    	if (!isset($param['mac'])) {
            $this->error('请求错误！');
    	}

	    $mac = $param['mac'];
    	$type = isset($param['type']) ? $param['type'] :0; //周 月 年
    	$dateTime = isset($param['date_time']) ? $param['date_time'] : strtotime(time()); //周 月 年
		$ToiletFlow = new ToiletFlowModel();
        $result['line'] = $ToiletFlow->getLineDate($type,$dateTime);
        $res = $ToiletFlow->getSatisfactionTagSum($mac,$type,$result['line']);
        $result['name']  = $res['name'];
        $result['data']  = $res['val'];
    	$this->success('success',$result);

    	
    }


}
